package com.zry.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * author : dut
 * e-mail : dt@xdja.com
 * date   : 2020/6/2
 * desc   :
 */
public class Dutao {
    public static void main(String[] args) {
        //总人数
        int count = 40;
        //几号被杀
        int killNum = 3;
        kill(count, killNum);

    }

    private static void kill(int count, int killNum) {
        int killIndex = 0;
        List<String> personList = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            String personNum = String.valueOf(i + 1);
            personList.add(personNum);
        }

        while (personList.size() > 1) {
            // 被杀的索引位置
            killIndex = (killIndex + killNum) % (personList.size()) - 1;

            if (killIndex < 0){

                System.out.println("Kill:" + personList.get(personList.size() -1));
                personList.remove(personList.size() -1);
                killIndex = 0;
            }else {
                System.out.println("Kill:" + personList.get(killIndex));
                personList.remove(killIndex);
            }

        }
        System.out.println("Live:" + personList.get(0));
    }
}
